﻿
using System;
using System.Collections.Generic;
using System.Linq;
using Tau.DataAccess;

namespace Tau.Service.Adapters
{
    internal class Page : IAdapter<Model.Page, tblPage>
    {
        public Model.Page GetModelObject(tblPage dbObject)
        {
            var model = new Model.Page
                                  {
                                      BolLeft = dbObject.bolLeft.GetValueOrDefault(),
                                      OrderId = dbObject.orderID.GetValueOrDefault(),
                                      PageCode = dbObject.pageCode,
                                      PageId = dbObject.pageID,
                                      PageName = dbObject.pageName,
                                      PageTitle = dbObject.pageTitle,
                                      TopNavId = dbObject.topNavID.GetValueOrDefault(),
                                      TopOrderId = dbObject.topOrderID.GetValueOrDefault(),
                                      ParentPageId = dbObject.parentPageID.GetValueOrDefault(),
                                      IsDisplayedToPublic = dbObject.display.GetValueOrDefault()
                                  };
            return model;
        }

        public tblPage GetDbObject(Model.Page model)
        {
            var dbObject = new tblPage()
                           {
                               bolLeft = model.BolLeft,
                               orderID = model.OrderId,
                               pageCode = model.PageCode,
                               pageID = model.PageId,
                               pageName = model.PageName,
                               pageTitle = model.PageTitle,
                               topNavID = model.TopNavId,
                               topOrderID = model.TopOrderId,
                               parentPageID = model.ParentPageId,
                               display = model.IsDisplayedToPublic
                           };
            return dbObject;
        }

        public List<Model.Page> GetModelList(List<tblPage> dbObjectList)
        {
            var pageList = dbObjectList.Select(dbPage => GetModelObject(dbPage)).ToList();
            return pageList;
        }
    }
}
